package com.leeyu.kafka.selfserial;

import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.ProducerRecord;
import org.apache.kafka.common.serialization.StringSerializer;

import java.util.Properties;

public class ProducerUser {

    public static void main(String[] args) {
        Properties properties = new Properties();
        properties.put("bootstrap.servers", "localhost:9092");
        properties.put("key.serializer", StringSerializer.class);
        properties.put("value.serializer", UserSerializer.class);

        try (KafkaProducer<String, User> producer = new KafkaProducer<>(properties)) {
            try {
                ProducerRecord<String, User> record = new ProducerRecord<>("topic1", new User(1, "leeyu"));
                producer.send(record);
                System.out.println("发送消息成功！");
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}
